//我要升级取消订单
function cancelOrder() {
	showLoading();
	$.ajax({
		url : appPath + '/dealerApply/cancelOrder.json',
		dataType : 'json',
		type : 'post',
		data : {
			token : $.cookie("token"),
			code : $('#code').val()
		},
		success : function(data) {
			hideLoading();
			if (data.code == -1) {
				myalert("请登录", function() {
					window.location = appPath + "/member/login.htm";
				})
				return;
			}
			if (data.code == 0) {
				myalert(data.msg);
				return;
			} else {
				myalert(data.msg, function() {
					gotoHtml('/center/center.htm')
				});

			}
		},
		error : function() {
			hideLoading();
			$.myalert("系统异常，请重试");
		}
	})

}

function zhifubao() {
	showLoading();
	$.ajax({
		url : appPath + '/pay/moneyPay.json',
		dataType : 'json',
		type : 'post',
		data : {
			token : $.cookie("token"),
			code : $('#code').val(),
			payChannel : 22
		},
		success : function(data) {
			hideLoading();
			if (data.code == -1) {
				myalert("请登录", function() {
					window.location = appPath + "/member/login.htm";
				})
				return;
			}
			if (data.code == 0) {
				myalert(data.msg);
				return;
			} else {
				$('#zhifubao').html(data.form);
				$('#pay_form').submit();
			}
		},
		error : function() {
			hideLoading();
			myalert("系统异常，请重试");
		}
	})
}
function weixin() {
	showLoading();
	$
			.ajax({
				url : appPath + '/pay/moneyPay.json',
				dataType : 'json',
				type : 'post',
				data : {
					token : $.cookie("token"),
					code : $('#code').val(),
					payChannel : 12
				},
				success : function(data) {
					hideLoading()
					if (data.code == -1) {
						myalert("请登录", function() {
							window.location = appPath + "/member/login.htm";
						})
						return;
					}
					if (data.code == 0) {
						myalert(data.msg);
						return;
					} else {
						$('#mainpay').html('');
						$(
								'<div class="tjdd" style="margin:auto;">'
										+ '<div style="width:1096px;height:110px;line-height:110px;text-align:center;border:#6e8ce2 2px solid;background:#c6d6fb;">'
										+ '<p style="line-height:110px;font-size:28px;color:#000;">微信支付</p></div>'
										+ '<div style="width:1100px;height:650px;padding-top:50px;">'
										+ '<div id="output" style="width:400px;height:400px;float:left;padding-left:150px;">'
										+ '<img alt="这是二维码" src="'
										+ appPath
										+ '/dealer/getQrcode.htm?content='
										+ data.form
										+ '&width=300&height=300"/>'
										+ '</div>'
										+ '<div style="width:300px;height:360px;float:left;background:url('
										+ $('#path').val()
										+ '/pcimages/wx11.png) no-repeat;"></div>'
										+ '<div style="clear:both"></div>'
										+ '<div style="width:770px;height:140px;margin-left:150px;">'
										+ '<ul>'
										+ '<li style="width:770px;height:70px;line-height:70px;text-align:center;border-bottom:#ddd 1px solid;">'
										+ '<h1 style="float:left;line-height:70px;padding-left:300px;">支付：</h1><span style="font-size:24px;color:#4672d5;line-height:70px;float:left;">￥'
										+ $('#money').val()
										/ 100
										+ '</span></li>'
										+ '<li style="width:770px;height:70px;line-height:70px;text-align:center;border-bottom:#ddd 1px solid;"><p style="float:left;line-height:70px;text-align:center;">温馨提示：如果您已完成微信支付，但页面无任何提示，请至</p>'
										+ '<a style="float:left;color:#4672d5;" href="javascript:gotoHtml(\'/buyer/buyer.htm\')" target="_blank">订单详情</a><p style="float:left;line-height:70px;text-align:center;">查看支付结果</p></li>'
										+ '</ul>' + '</div>' + '</div>'
										+ '</div>').appendTo($('#mainpay'));
						setInterval("checkOrder(" + $('#code').val() + ")",
								3000);
					}
				},
				error : function() {
					hideLoading();
					myalert("系统异常，请重试");
				}
			});
}
function checkOrder(code) {
	$.ajax({
		url : appPath + '/pay/checkOrder.json',
		dataType : 'json',
		type : 'post',
		data : {
			token : $.cookie("token"),
			code : code
		},
		success : function(data) {
			if (data.code == -1) {
				myalert("请登录", function() {
					window.location = appPath + "/member/login.htm";
				})
				return;
			}
			if (data.code == 0) {
				return;
			} else {
				gotoHtml('/pay/result.htm?result=true');
			}
		}
	})
}
function tc_center_balance() {
	var _top = (screen.height - $("#balancePopup").height()) / 3;
	var _left = (screen.width - $("#balancePopup").width()) / 2;

	$("#balancePopup").css({
		top : _top,
		left : _left
	});
}
function balance() {

	$("#cover").show();
	$("#balancePopup").show();
	tc_center_balance();
	$("#guanbi").unbind('click');
	$("#queding").unbind('click');
	$("#guanbi").click(function() {
		$("#cover").hide();
		$("#balancePopup").hide();
	})
	$("#queding").click(function() {
		$("#cover").hide();
		$("#balancePopup").hide();
		balancePay();
		return;
	})
}
function balancePay() {
	var pass = $('#password').val();
	if (pass.length < 1) {
		myalert("请输入支付密码");
		return;
	}
	showLoading();
	$.ajax({
		url : appPath + '/pay/balancePay.json',
		dataType : 'json',
		type : 'post',
		data : {
			token : $.cookie("token"),
			payPass : $.md5(pass + $('#key').val()),
			code : $('#code').val()
		},
		success : function(data) {
			hideLoading();
			if (data.code == -1) {
				myalert("请登录", function() {
					window.location = appPath + "/member/login.htm";
				})
				return;
			}
			if (data.code == 0) {
				myalert(data.msg);
				return;
			} else {
				myalert(data.msg, function() {
					gotoHtml('/pay/result.htm?result=true');
				});

			}
		},
		error : function() {
			hideLoading();
			myalert("系统异常，请重试");
		}
	})
}